package com.gitee.yannzh.rune.support.crud.util;

/**
 * @author Yann
 * @date 2025/5/15 16:58
 * @description
 * @since 1.0.0
 */

import com.gitee.yannzh.rune.support.crud.constants.ViewType;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Arrays;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class TypeUtil {

    private static final String[] NUMBER_TYPES = new String[]{
            "int", "long", "double", "float", "short", "byte",
            "BigDecimal", "Integer", "Long", "Double", "Float", "Short", "Byte"
    };
    private static final String[] STRING_TYPES = new String[]{"String", "char"};

    private static final String[] DATE_TYPES = new String[]{"LocalDate"};
    private static final String[] DATETIME_TYPES = new String[]{"Date", "LocalDateTime"};
    private static final String[] TIME_TYPES = new String[]{"LocalTime"};

    public static ViewType mappingType(String typeName) {
        if (Arrays.asList(STRING_TYPES).contains(typeName)) {
            return ViewType.TEXT;
        }
        if (Arrays.asList(NUMBER_TYPES).contains(typeName)){
            return ViewType.NUMBER;
        }
        if (Arrays.asList(DATE_TYPES).contains(typeName)){
            return ViewType.DATE;
        }
        if (Arrays.asList(DATETIME_TYPES).contains(typeName)){
            return ViewType.DATETIME;
        }
        if (Arrays.asList(TIME_TYPES).contains(typeName)){
            return ViewType.TIME;
        }

        return ViewType.TEXT;
    }

}
